/*
 * rtos.c
 *
 * Created: 14/12/2013 19:20:57
 *  Author: usuario
 */ 

#include <asf.h>
#include <console.h>
//#include <blackbox.h>

#include "rtos.h"


static char vASSERT;


void RTOS_setup()
{
	vASSERT=0;
	
	vTraceInitTraceData();
	
	uiTraceStart();
}

void RTOS_start( void )
{
	vTaskStartScheduler();
	
	puts("\r\nEXECUTION STOPPED FOR DEBUGGING - INSUFFICIENT HEAD MEMORY -\r\n");
	configASSERT(NULL);
	taskDISABLE_INTERRUPTS();
	for( ;; );
	
}

void vApplicationMallocFailedHook( void )
{
	puts("\r\nEXECUTION STOPPED FOR DEBUGGING - MALLOC FAILED -\r\n");
	configASSERT(NULL);
	taskDISABLE_INTERRUPTS();
	for( ;; );
}

void vApplicationIdleHook( void )
{
	sleepmgr_enter_sleep();
}

void vApplicationStackOverflowHook( xTaskHandle pxTask, signed char *pcTaskName )
{
	( void ) pcTaskName;
	( void ) pxTask;

	puts("\r\nEXECUTION STOPPED FOR DEBUGGING - STACK OVERFLOW -\r\n");
	configASSERT(NULL);
	taskDISABLE_INTERRUPTS();
	for( ;; );
}

void vApplicationTickHook( void )
{
}

void vConfigASSERT( void )
{
	CONSOLE_write((char *) "\r\nWARNING - configASSERT RAISED\r\n");
	//BLACKBOX_save_current_trace("vConfigASSERT");
	vASSERT=1;
	
	//taskDISABLE_INTERRUPTS();
}

uint8_t check_assert()
{
	return vASSERT;
}